using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using AxTWSLib;

namespace TradingPlatform.IB.Operations
{
    public class AllOpenOrders
    {
        private readonly AxTws _tws;

        public SortedList<int, List<int>> _result;

        public AllOpenOrders(AxTws tws)
        {
            _tws = tws;

            _tws.orderStatus += new _DTwsEvents_orderStatusEventHandler(_tws_orderStatus);
            _result = new SortedList<int, List<int>>();
        }

        public void RequestOpenOrders()
        {
            _result.Clear();
            _tws.reqAllOpenOrders();
        }

        void _tws_orderStatus(object sender, _DTwsEvents_orderStatusEvent e)
        {
            int clientId = e.clientId;
            int orderId = e.id;
            if (!_result.ContainsKey(clientId))
            {
                _result.Add(clientId,new List<int>());
            }
            _result[clientId].Add(orderId);
        }
    }
}